// pages/welfare/index.js
import ddt from '../../api/axios.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeone:[{
    name:'精品外卖'
  },{
    name:'精品外卖'
  },{
    name:'精品外卖'
  },{
    name:'精品外卖'
  }],
  curr:0,
  option1: [
    { text: '全部商品', value: 0 },
    { text: '新款商品', value: 1 },
    { text: '活动商品', value: 2 },
  ],
  option2: [
    { text: '默认排序', value: 'a' },
    { text: '好评排序', value: 'b' },
    { text: '销量排序', value: 'c' },
  ],
  value1: 0,
  value2: 'a',
  shoplist:[],
  address:'',
  addresslist:'',
  userinfo:'',
  },
  addgopath(){
    if (wx.getStorageSync('userinfo') == ''){
      wx.showModal({
        title: '提示',
        content: '是否前往登陆',
        success (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '../login/login',
            })
          }
        }
      })
    }else{
      wx.navigateTo({
        url: '../address/index?id=' + 1,
      })
    }
    
  },
  typegopath(u){
    var url = u.currentTarget.dataset.url
      wx.navigateTo({
        url,
      }) 
  },
  addressinfo(){
    ddt('get', '/api/user/addresslist').then(res => {
      this.setData({
        addresslist: res.data.data,
        address: res.data.data[0].address
      })
    })
  },
  gopath(e){
    var url = e.currentTarget.dataset.url
    wx.navigateTo({
      url,
    })
  },
  shoplist(){
    ddt('get', '/api/indexshops?page=' + 1).then(res => {
      this.setData({
        shoplist: res.data.data
      })
      wx.setStorageSync('imgurl', res.data.data.url)
      console.log(res)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    if (typeof this.getTabBar === 'function' &&
    this.getTabBar()) {
    this.getTabBar().setData({
      selected: 1
    })
  }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      userinfo:wx.getStorageSync('userinfo')
    })
    if(this.data.param== undefined){
      this.addressinfo()

    }else{
      this.setData({
        address:this.data.param
      })
    }
this.shoplist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})